DATA SEGMENT
    string DB 'hello world!',0DH, 0AH, '$'
    ;当前处于表中位置
    TABLE_X         DW  0H
    TABLE_Y         DW  0H
DATA ENDS

EXTRA SEGMENT
    ;#######键入鼠标的宏########
    ;主要功能是键入鼠标，物理坐标保存到SCREEN_X,SCREEN_Y,把左右键保存到SI里
    ;SI,0是左键,FFFFH是右键
    ;参数:DW SCREEN_X,DW SCREEN_Y
    GET_MOUSE MACRO SCREEN_X,SCREEN_Y
        PUSH AX
        PUSH BX
        PUSH CX
        PUSH DX
        ;调用33H中断
        ;入口参数：AX＝03H
        ;出口参数：BX＝按键状态：位0=1——按下左键位,1=1——按下右键位,2=1——按下中键
        GETMOUSE:
            MOV AX,03H
            INT 33H
            AND BX,00000011B
            CMP BX,0
            JZ  GETMOUSE
        ;保存横纵坐标
        ; MOV AX,CX
        ; DIV 16
        MOV SCREEN_X,CX
        MOV SCREEN_Y,DX
        ;检查是否为左键
        CMP BX,00000001B
        JZ  LEFT_MOUSE
        RIGHT_MOUSE:
            ;右键置SI为FFFFH
            MOV SI,0FFFFH
            JMP END_GET_MOUSE
        LEFT_MOUSE:
            ;左键置SI为0
            MOV SI,0
            JMP END_GET_MOUSE
        END_GET_MOUSE:
        POP DX
        POP CX
        POP BX
        POP AX
    ENDM
    
EXTRA ENDS

CODE SEGMENT
    ASSUME CS:CODE,DS:DATA,ES:EXTRA
START:MOV AX,DATA
      MOV DS,AX
      MOV AX,EXTRA
      MOV ES,AX
      MOV AH,0
      MOV AL,03H  ;80*25 16色文本
      INT 10H
      GET_MOUSE TABLE_Y,TABLE_X
      LEA DX, string
		MOV AH, 09H
		INT 21H
    HLT
CODE ENDS
      END START